window.vm = new Vue({
    el: '#app',
    data: {

        //评分
        imageUrl: '',
        rate: null,
        oneNo:'',
        onePro:'',
        text:['非常不满意','不满意','一般','满意','非常满意'],
        rateRemark: '',
        list: [],

        rules: {
            subject: [
                { required: true, message: '请输入主题名称', trigger: 'blur' },
                { min: 0, max: 50, message: '长度在 0 到 50 个字符', trigger: 'blur' }
            ],
            questionType: [
                { required: true, message: '请选择问题类型', trigger: 'blur' },
            ],
            content: [
                { required: true, message: '请填写内容', trigger: 'blur' }
            ],
            etime: [
                { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
            ],
            date2: [
                { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
            ],
            type: [
                { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
            ],
            resource: [
                { required: true, message: '请选择活动资源', trigger: 'change' }
            ],
            desc: [
                { required: true, message: '请填写活动形式', trigger: 'blur' }
            ]
        }

        // activeName: 'second',
        // accepted: 0
    },
    methods: {

        handleChange(file, fileList) {
            console.log(this.list.at(0))
            this.list = fileList.slice(-3);
        },

        handleAvatarSuccess(res, file) {
            this.imageUrl = URL.createObjectURL(file.raw);
            this.process.questionPhoto = file.name;
        },
        beforeAvatarUpload(file) {
            // const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 10;

            // if (!isJPG) {
            //     this.$message.error('上传头像图片只能是 JPG 格式!');
            // }
            if (!isLt2M) {
                this.$message.error('上传文件大小不能超过 10MB!');
            }
            // return isJPG && isLt2M;
            return isLt2M
        },

        oneBack:function (){
            top.location.href = "userProcess.html"
        },



        submitOnePro:function (){

            // if (this.list != null)
            //     this.onePro.fileList = this.list
            if(vm.onePro.fileList)
                vm.onePro.fileList = vm.onePro.fileList.join(', ')
            this.$confirm('确认修改', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                axios({
                    method: 'post',
                    url: '/updateProcess',
                    headers:{
                        'Context-Type': 'application/json' // 1
                    },
                    data: this.onePro// 2
                }).then((res) => {
                    top.location.href = "userProcess.html"
                });
                this.$message({
                    type: 'success',
                    message: '已修改!'
                });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消!'
                });
            });

        },

        isDelete:function (){
            this.$confirm('确认删除', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                vm.onePro.isDelete = 0
                if(vm.onePro.fileList)
                    vm.onePro.fileList = vm.onePro.fileList.join(', ')
                axios({
                    method: 'post',
                    url: '/updateProcess',
                    headers:{
                        'Context-Type': 'application/json' // 1
                    },
                    data: this.onePro// 2
                }).then((res) => {
                    top.location.href = "userProcess.html"
                });
                this.$message({
                    type: 'success',
                    message: '已删除!'
                });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消!'
                });
            });


        },


    },
    created: function () {

        let params = new URLSearchParams(window.location.search);
        let processNo
        if(params.get("processNo"))
            processNo = JSON.parse(params.get("processNo"))
        else
            processNo = JSON.parse(sessionStorage.getItem("processNo"))

        axios.get(
            "/getPro",{
                params: {
                    processNo: processNo
                }
            }
        ).then(function (res) {
            vm.onePro = res.data
            if(vm.onePro.fileList)
                vm.onePro.fileList = vm.onePro.fileList.split(", ")
        }).catch(e => {
            ajaxError(vm, e);
        });


    },
});


